package com.ruoyi.performance.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.performance.domain.PerfLevelTemplate;
import com.ruoyi.performance.domain.PerfMitemDitem;
import com.ruoyi.performance.domain.PerfTemplateDitem;
import com.ruoyi.performance.dto.PerfTemplateDitemDto;
import com.ruoyi.performance.service.PerfTemplateDitemService;
import com.ruoyi.performance.utils.MyUtils;

import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author YL
 * @date 2020-07-22
 * @description 绩效模板细项控制层
 */
@RestController
@RequestMapping("templateditem")
public class PerfTemplateDitemController extends MyUtils {
	
	@Resource
	private PerfTemplateDitemService perfTemplateDitemService;

	/**
     * 根据id查找绩效模板细项
     * @param id 绩效模板细项id
     * @return 绩效模板细项明细
     */
	@GetMapping("get")
	public R list(int id){
		Map<String, Object> m = new HashMap<>(16);
		m.put("rows", perfTemplateDitemService.selectPerfTemplateDitemById(id));
		return R.ok(m);
	}

	/**
	 * 根据公司代码查找细项
	 */
	@GetMapping("getbycode")
	public R list(String companyCode) {
		startPage();
		return result(perfTemplateDitemService.selectPerfTemplateDitemByCompanyCode(companyCode));
	}

	/**
	 * 查询绩效模板细项明细列表
	 */
	@GetMapping("list")
	public R list(PerfTemplateDitemDto perfTemplateDitemDto) {
		startPage();
        return result(perfTemplateDitemService.selectPerfTemplateDitemList(perfTemplateDitemDto));
	}
	
	/**
	 * 新增保存绩效模板细项明细
	 */
	@PostMapping("save")
	public R addSave(@RequestBody PerfTemplateDitem perfTemplateDitem) {
		return toAjax(perfTemplateDitemService.insertPerfTemplateDitem(perfTemplateDitem));
	}

	/**
	 * 修改保存绩效模板细项明细
	 */
	@PostMapping("update")
	public Map<String,String> editSave(@RequestBody Map<String, List<PerfTemplateDitem>> datas) {
		return jacResultMsg(perfTemplateDitemService.updatePerfTemplateDitem(datas));
	}
	
	/**
	 * 删除绩效模板细项
	 */
	@PostMapping("remove")
	public Map<String,String> remove(String ids){
		return jacResultMsg(perfTemplateDitemService.deletePerfTemplateDitemById(ids));
	}

	/**
	 * 添加主项、细项关联关系
	 */
	@PostMapping("addlink")
	public R addlink(@RequestBody PerfMitemDitem perfMitemDitem){
		return toAjax(perfTemplateDitemService.insertPerfMitemDitem(perfMitemDitem));
	}

	/**
	 * 删除主项、细项关联关系
	 */
	@PostMapping("removelink")
	public Map<String,String> removelink(@RequestBody Map<String, List<PerfMitemDitem>> datas){
		return jacResultMsg(perfTemplateDitemService.deletePerfMitemDitem(datas));
	}
}
